﻿@{
    ViewBag.Title = "Gestión de Socios";
}
<h3>
    Gestión de Socios</h3>
<div>
@*    @using (Html.BeginForm("GetList", "Socio", FormMethod.Get, new { @class = "form-search" }))
    {

    }*@
    <fieldset>
        <legend>Busqueda</legend>
        <input id="filtroNombre" type="text" class="input-medium search-query" placeholder="Nombre" />
        <input id="filtroApellido" type="text" class="input-medium search-query" placeholder="Apellido" />
        <input id="filtroDNI" type="text" class="input-medium search-query" placeholder="Documento" />
        <button id="btnBuscar" type="submit" class="btn btn-primary">
            Buscar</button>
    </fieldset>
    <br/>
    <table id="grid">
    </table>
    <div id="pager">
    </div>
</div>
<br />
<div class="text-right">
    <a href="@Url.Action("Index", "Home")" class="btn">Volver</a> <a href="@Url.Action("Create", "Socio")" class="btn btn-success">
        Nuevo</a>
</div>
<script type="text/javascript">
    $(document).ready(function () {
        var code = null;
        $("#filtroNombre").keypress(function (e) {
            code = (e.keyCode ? e.keyCode : e.which);
            if (code == 13) $("#grid").trigger('reloadGrid');
        });

        $("#filtroApellido").keypress(function (e) {
            code = (e.keyCode ? e.keyCode : e.which);
            if (code == 13) $("#grid").trigger('reloadGrid');
        });

        $("#filtroDNI").keypress(function (e) {
            code = (e.keyCode ? e.keyCode : e.which);
            if (code == 13) $("#grid").trigger('reloadGrid');
        });

        $("#btnBuscar").click(function () {
            $("#grid").trigger('reloadGrid');
        });

        $("#grid").jqGrid({
            datatype: function (pData) { getData(pData); },
            colNames: ['Id', 'Nombre', 'Apellido', 'Documento', 'Fecha Ingreso', 'Domicilio', 'Localidad', 'Telefono', '', '', ''],
            colModel: [
                   { name: 'Id', index: 'Id', width: '100%', hidden: true, key: true },
                   { name: 'Nombre', index: 'Nombre', width: '100%', align: 'left' },
                   { name: 'Apellido', index: 'Apellido', width: '100%', align: 'left' },                   
                   { name: 'Documento', index: 'Documento', width: '100%', align: 'right' },
                   { name: 'FechaIngreso', index: 'FechaIngreso', width: '100%', align: 'center', datefmt: 'Y-m-d H:i:s' },
                   { name: 'Domicilio', index: 'Domicilio', width: '100%', align: 'left' },
                   { name: 'Localidad', index: 'Localidad', width: '100%', align: 'left' },
                   { name: 'Telefono', index: 'Telefono', width: '100%', align: 'right' },
                   { index: 'details', formatter: imgLinkFormater, width: '10', sortable: false, search: false, linkUrl: '@Url.Action("Details")/', imgSrc: '@Url.Content("~/Content/img/icon_details.png")' },
                   { index: 'edit', formatter: imgLinkFormater, width: '10', sortable: false, search: false, linkUrl: '@Url.Action("Edit")/', imgSrc: '@Url.Content("~/Content/img/icon_modify.gif")' },
                   { index: 'delete', formatter: imgLinkFormater, width: '10', sortable: false, search: false, linkUrl: '@Url.Action("Delete")/', imgSrc: '@Url.Content("~/Content/img/icon_delete.gif")' }
                   ],
            pager: $('#pager'),
            rowNum: 10,
            rowList: [10, 20, 50, 100],
            sortname: 'Id',
            sortorder: 'asc',
            viewrecords: true,
            imgpath: '/Content/flick/images',
            caption: 'CONSULTA DE SOCIOS',
            autowidth: true,
            height: 'auto',
            jsonReader: { repeatitems: false, id: "Id" }
        }).navGrid('#pager', { search: false, edit: false, add: false, del: false, refresh: false });

        function getData(pData) {
            BlockScreen('Cargando datos');
            var params = new Object();
            params.sidx = pData.sidx;
            params.sord = pData.sord;
            params.page = pData.page;
            params.rows = pData.rows;

            if ($("#filtroNombre").val() != "") {
                params.name = $("#filtroNombre").val();
            }
            else {
                params.name = null;
            }
            if ($("#filtroApellido").val() != "") {
                params.lastname = $("#filtroApellido").val();
            }
            else {
                params.lastname = null;
            }
            if ($("#filtroDNI").val() != "") {
                params.dni = $("#filtroDNI").val();
            }
            else {
                params.dni = null;
            }

            SendAjax("GET", true, '@Url.Action("GetList")', params,
                   function (data, textStatus) {
                       if (textStatus == "success") {
                           var grid = $("#grid")[0];
                           grid.addJSONData(data);
                           $.unblockUI();
                       }
                   });
        }
    }); 
</script>
